package com.sbj.dto.res;

import cn.zhxu.bs.bean.DbField;
import cn.zhxu.bs.bean.DbIgnore;
import cn.zhxu.bs.bean.SearchBean;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.sbj.dto.jackson.CustomDecimalSerialize;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.Bidi;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * @author summer
 * @version 1.0
 * @date 2024/8/10 15:42
 */
@Data
@SearchBean(tables = " member m LEFT JOIN " +
        " (SELECT count(*) as num, inviter FROM member GROUP BY inviter ) m1 ON m.inviter_code=m1.inviter" +
        " LEFT JOIN  (SELECT count(*) as logNum,member_id FROM member_logistics GROUP BY member_id ) l ON l.member_id=m.id",autoMapTo = "m",orderBy = "m.createTime DESC")
public class MemberRes implements Serializable {

    @DbField("m.id")
    private Integer id;

    @DbField("CASE WHEN l.logNum  IS NULL THEN 0 ELSE 1 END ")
    private Integer logNum;

    @DbField("m.startTime")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private LocalDateTime startTime;

    @DbField("m.endTime")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private LocalDateTime endTime;

    @DbField("m.is_privilege")
    private Boolean isPrivilege;

    @DbField("CASE WHEN m.is_privilege=1 THEN '是' ELSE '否' END")
    private String privilegeName;

    @DbField("m.nickName")
    private String nickName;

    @DbField("m.inviter_code")
    private String inviterCode;

    @DbField("m1.num")
    private Integer inviterNum;

    @DbField("m.phone")
    private String phone;

    @DbField("m.avatar_image")
    private String image;

    @DbField("m.coupons")
    @JsonSerialize(using = CustomDecimalSerialize.class)
    private BigDecimal coupons;

    @DbField("m.extension")
    @JsonSerialize(using = CustomDecimalSerialize.class)
    private BigDecimal extension;

    @DbField("m.balance")
    @JsonSerialize(using = CustomDecimalSerialize.class)
    private BigDecimal balance;

    @DbField("m.bonus")
    @JsonSerialize(using = CustomDecimalSerialize.class)
    private BigDecimal bonus;

    @DbField("m.createTime")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private LocalDateTime createTime;

    @DbIgnore
    private String token;
}
